<template>
  <div class="app-container-custom">
      <el-row :gutter="10" class="mb8">
        <el-col :span="24">
          <el-form :inline="true" :model="queryParams" ref="queryForm"  size="small" label-width="0" class="demo-form-inline" style="height: 40px;float: right;">
            <el-form-item prop="costNo">
              <el-input
                v-model="queryParams.costNo"
                placeholder="费用单号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>

            <el-form-item style="width: 100px;" prop="status">
              <el-select v-model="queryParams.status" placeholder="收全状态" clearable size="small">
                <el-option
                  v-for="dict in statusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
            <el-form-item >
              <el-date-picker
                v-model="fullReceiptDate"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="收全日期开始"
                end-placeholder="收全日期结束">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>

<!--      <el-row :gutter="10" class="mb8">-->
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="primary"-->
<!--            plain-->
<!--            size="mini"-->
<!--            @click="handleBailRefund"-->
<!--            :disabled="currentNode.modelType == 'dept'"-->
<!--          >保证金退款</el-button>-->
<!--        </el-col>-->
<!--      </el-row>-->
      <el-table
        v-loading="loading"
        :data="ruleCostList"
        @selection-change="handleSelectionChange"
        border
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="单据号" align="center" prop="costNo" width="120"/>
        <el-table-column label="收费类型" align="center" prop="projectId" width="120" :formatter="projectFormat"/>
        <el-table-column label="收费项目" align="center" prop="chargeId" width="120" :formatter="itemFormat"/>
        <el-table-column label="应收日期" align="center" prop="receivableTime" width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.receivableTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="单价" align="center" prop="prices" width="60" />
        <el-table-column label="应收金额" align="center" prop="receivableMoney"  width="100"/>
        <el-table-column label="已收金额" align="center" prop="haveMoney"  width="100"/>
        <el-table-column label="收全日期" align="center" prop="fullReceiptDate" width="120">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.fullReceiptDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  </div>
</template>

<script>
import { listRuleCost,bailRefund } from "@/api/payfee/ruleCost";
import { listItem } from "@/api/payfee/item";
import { listProject} from "@/api/payfee/project";


export default {
  //保证金列表
  name: "bailRuleCostList",
  data() {
    return {
      toggleSearchStatus:false,
      sideshow:true,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 常规费用单表格数据
      ruleCostList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        costNo: null,
        roomId: null,
        deptId: null,
        ownerId: null,
        projectId: '03',
        chargeId: null,
        normId: null,
        roomNormId: null,
        receivableTime: null,
        beginTime: null,
        finishTime: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      currentNode:{},
      //收费项目字典
      itemOptions:[],
      //收费类型字典
      projectOptions:[],
      currentOptions:[],
      fullReceiptDate:[] //收全日期
    };
  },
  created() {
    this.getDicts("charge_status").then(response => {
      this.statusOptions = response.data;
    });
    listItem().then(res=>{
      this.itemOptions = res.rows;
    })
    listProject().then(res=>{
      this.projectOptions = res.rows;
    })
  },
  methods: {
    init(options){
      this.currentOptions = options
      this.getList();
    },
    /** 查询常规费用单列表 */
    getList() {
      this.loading = true;
      this.queryParams.roomId = this.currentOptions.roomIds||"-1"
      let queryParams = this.addDateRange(this.queryParams,this.fullReceiptDate,"fullReceiptDate")
      listRuleCost(queryParams).then(response => {
        this.ruleCostList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 收费项目字典翻译
    itemFormat(row, column) {
      let index = this.itemOptions.findIndex(x=>x.chargeId == row.chargeId);
      if(index != -1){
        return this.itemOptions[index].chargeName
      }
      return '';
    },
    // 收费类型字典翻译
    projectFormat(row, column) {
      let index = this.projectOptions.findIndex(x=>x.projectId == row.projectId);
      if(index != -1){
        return this.projectOptions[index].projectType
      }
      return '';
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.fullReceiptDate = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.costId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleBailRefund(){
      //bailRefund
    }
  }
};
</script>
